import 'package:cloud_music/application.dart';
import 'package:cloud_music/core/viewmodels/theme_model.dart';
import 'package:cloud_music/core/viewmodels/user_model.dart';
import 'package:cloud_music/route/navigate_service.dart';
import 'package:cloud_music/route/routes.dart';
import 'package:cloud_music/ui/pages/splash_page.dart';
import 'package:cloud_music/utils/log_util.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'application.dart';
// import 'package:cloud_music/route/router.dart' as router;

void main() {
  //路由
  Router router = Router();
  Application.router = router;
  Routes.configureRoutes(router);
  // 初始化全局状态数据
  Application.setupLocator();
  // 日志输出
  LogUtil.init(tag: 'cloud_music');
  // Provider如果与Listenable/一起使用，现在抛出Stream。考虑使用ListenableProvider/ StreamProvider代替。或者，可以通过设置Provider.debugCheckInvalidValueType 为null这样来禁用此异常***/
  //Provider.debugCheckInvalidValueType = null;
  runApp(MultiProvider(
    providers: [
      ChangeNotifierProvider<UserModel>(
        create: (_) => UserModel(),
      ),
      ChangeNotifierProvider<ThemeModel>(
        create: (_) => ThemeModel(ThemeType.Light),
      )
    ],
    child: MyApp(),
  ));
}

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // 构造一个App基本界面
    return MaterialApp(
      // debugShowCheckedModeBanner: false,
      title: 'Flutter Starter',
      onGenerateRoute: Application.router.generator,
      // 可以实现 在别处没有context环境下调用Navigator
      navigatorKey: Application.locator<NavigateService>().key,
      // 监听主题变化, listen: true
      theme: Provider.of<ThemeModel>(context, listen: true).themeData,
      // 和上面一样
      // onUnknownRoute: // 不建议采用，将导航的业务逻辑混入到了View层中
      home: SplashPage(),
    );
  }
}
